<template>
    <div> 
        <div class="sidebar">
            <el-menu
                class="sidebar-el-menu"
                :default-active="onRoutes"
                :collapse="sidebar.collapse"
                background-color="#324157"
                text-color="#bfcbd9"
                active-text-color="#20a0ff"
                unique-opened
                router
            >
            <a class="login-logo" href="/"><img :src="img" /></a>
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-sub-menu :index="item.index" :key="item.index" v-permiss="item.permiss">
                        <template #title>
                            <el-icon>
                                <component :is="item.icon"></component>
                            </el-icon>
                            <span class="temp">{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <template v-if="subItem.subs">
                                <el-sub-menu
                                    :index="subItem.index"
                                    :key="subItem.index"
                                    v-permiss="subItem.permiss"
                                >
                                    <template #title> <div class="temp">{{ subItem.title }}</div></template>
                                    <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index" >
                                        {{ threeItem.title }}
                                    </el-menu-item>
                                </el-sub-menu>
                            </template>
                            <template v-else>
                                <el-menu-item :key="subItem.index" :index="subItem.index" v-permiss="subItem.permiss">
                                    {{ subItem.title }}
                                </el-menu-item>
                            </template>
                        </template>
                    </el-sub-menu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index" v-permiss="item.permiss">
                        <el-icon>
                            <component :is="item.icon"></component>
                        </el-icon>
                        <template #title>{{ item.title }}</template>
                    </el-menu-item>
                </template>
            </template>
            </el-menu>
        </div>
    </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useSidebarStore } from '@/store/sidebar';
import { useRoute } from 'vue-router';
import img from '@/assets/img/Loginlogo.png';
const items = [
    {
        icon: 'Odometer',
        index: '/dashboard',
        title: '系统首页',
        permiss: '1',
    },
    {
        icon: 'User',
        index: '8',
        title: '用户',
        permiss: '7',
        subs: [
            {
                index: '/user/add',
                title: '用户管理',
                permiss: '7',
            },
            {
                icon: 'Calendar',
                index: '4',
                title: '用户权限',
                permiss: '72',
                subs: [
                    {
                        index: '/user/permiss',
                        title: '权限',
                        permiss: '72',
                    },
                ],
            },
        ],
    },
];

const route = useRoute();
const onRoutes = computed(() => {
    return route.path;
});

const sidebar = useSidebarStore();
</script>

<style scoped>
.el-menu-item {
    font-size: 18px;
}

.temp {
    font-size: 18px;
}
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 0px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
.login-logo{
    /* margin-bottom: 5px; */
    text-align:center
}
.login-logo img{
    /* display: block; */
    width: 0%;
    margin: auto 0;
    /* margin: 0 20; */
}
</style>
